<template>
	<view class="content">
		<image class="headicon":src="userinfo.headicon">
		</image>
		<text>{{userinfo.name}}</text>
		<view class="entry-wrapper">
			<view>
				<image src="../../static/liuyanzhi.png"></image>我的留言
			</view>
			<view>
				<image src="../../static/pinglun.png"></image>我的评论
			</view>
			<view>
				<image src="../../static/shoucang.png"></image>我的收藏
			</view>
		</view>
		<view class="text-area">
			<button v-if="!flag" type="primary" @click="toLogin">点击登录</button>
		</view>
		<view class="button">
			<button type="primary" :disabled="!flag" size="default" @click="logout">退出</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userinfo: {
					userid: '001',
					name: 'toy',
					headicon: '/static/head_icon.png'
				},
				flag: false
			}
		},
		onShow() {
			uni.getStorage({
						key: "userinfo",
						success: (res) => {
							uni.showToast({
								title: '已登录'
							});
							this.flag = true
							this.userinfo.userid = res.data.id
							this.userinfo.headicon = '/static/images/tx.jpg'
							this.userinfo.name = res.data.name
						},
						fail: (err) => {
							uni.showToast({
								title: '未登录',
								icon: 'none'
							});
							this.flag = false
							}
						})
				},
				methods: {
					toLogin() {
						uni.navigateTo({
							url: '/pages/my/login'
						})
					},
					logout() {
						// 1. 清理缓存
						uni.clearStorageSync()
						// 2. 修改flag为false
						this.flag = false
						// 3. 清理当前页面的数据 
						this.userinfo = {}
					}
				}
		}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.head {
		display: flex;
		flex-direction: row;
		align-items: center;
		padding-left: 100rpx;
		align-self: flex-start;
	}

	.head>image {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
		margin-right: 50rpx;
	}

	.head>text {
		margin-top: 30rpx;
	}

	.entry-wrapper {
		margin-top: 80rpx;
		margin-bottom: 80rpx;
		width: 95%;
	}

	.entry-wrapper>view>image {
		width: 48rpx;
		height: 48rpx;
	}

	.entry-wrapper>view {
		width: 100%;
		height: 3em;
		line-height: 3em;
		border-bottom: 1px solid #CCC;
		text-indent: 1em;
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.entry-wrapper>view:first-child {
		border-top: 1px solid #CCC;
	}

	.button {
		width: 95%;
	}
	.headicon{
		width: 150rpx;
		height: 150rpx;
	}
	.text-area{
		width: 95%;
	}
</style>